<script src="theme/js/page.js"></script>
<style>
	.layui-layer-content{background:none;}
</style>
<div class="main_content">
	<div class="condition">
		<!-- 标题 -->
		<div class="content_top">
			<div class="content_title">证件申请</div>
			<!-- 操作区域 -->
			<div class="content_export">
				<a href="javascript:;" class="btn btn-sm col_export icon icon-download-alt mright5" link="apply-apply" title="数据导出"></a>
				<div class="dropdown mright5" title="数据列筛选">
					<a href="javascript:;" class="btn btn-sm icon icon-cogs" data-toggle="dropdown"></a>
					<ul class="dropdown-menu table_cell_list dropdown-menu-my"></ul>
				</div>
				<a href="#" class="btn btn-sm icon icon-th-large switch_search mright5" switchtype="0" title="高级搜索"></a>
			</div>
			<!-- 清除浮动 -->
			<div class="clearfix"></div>
		</div>

		<!-- 搜索区域 -->
		<form class="form-inline collection_form conditions">
			<?php if($_COOKIE['role']==3){ ?>
				<div class="form-group">
					<label class="control-label pull-left">所属县局：</label>
					<div class="pull-left" style="width:186px;">
						<select class="chosen-single select_query form-control sel area_type" name="area_type" style="width:186px;">
							<option value="">请选择所属县局</option>
							<?php foreach($companyList as $key=>$val){?>
								<option value="<?php echo $val->role_area;?>" <?php echo $area_type == $val->role_area ? 'selected' : '';?>><?php echo $val->area;?></option>
							<?php } ?>
						</select>
					</div>
				</div>
			<?php } ?>
			<div class="form-group">
				<label class="control-label pull-left">环节名称：</label>
				<div class="pull-left progress-type" style="width:186px;">
					<select class="chosen-single select_query form-control sel type_name" name="type_name" style="width:186px;">
						<option value="">请选择环节名称</option>
						<?php foreach($typeList as $key=>$val){?>
							<option value="<?php echo $val->progress;?>" <?php echo $type_name == $val->progress ? 'selected' : '';?>><?php echo $val->progress;?></option>
						<?php } ?>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="control-label pull-left">采集中队：</label>
				<div class="pull-left progress-type" style="width:186px;">
					<select class="chosen-single select_query form-control sel apply_squadron" name="apply_squadron" style="width:186px;">
						<option value="">请选择中队名称</option>
						<?php foreach($squadron as $key=>$val){?>
							<option value="<?php echo $val->squadron;?>" <?php echo $apply_squadron == $val->squadron ? 'selected' : '';?>><?php echo $val->squadron;?></option>
						<?php } ?>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="control-label pull-left">申请类型：</label>
				<div class="pull-left" style="width:186px;">
					<select class="chosen-single select_query form-control sel" name="apply_type" style="width:186px;">
						<option value="">请选择申请类型</option>
						<?php foreach($apply_type as $key=>$val){?>
							<option value="<?php echo $key;?>" <?php echo $apply_types == $key ? 'selected' : '';?>><?php echo $val;?></option>
						<?php } ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label pull-left">完成状态：</label>
				<div class="pull-left" style="width:186px;">
					<select class="chosen-single select_query form-control sel" name="complete" style="width:186px;">
						<option value="">请选择完成状态</option>
						<?php foreach($completes as $k=>$v){?>
							<option value="<?php echo $k;?>" <?php echo $complete == $k ? 'selected' : '';?>>
								<?php echo $v;?>
							</option>
						<?php } ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label pull-left">办理类型：</label>
				<div class="pull-left" style="width:186px;">
					<select class="chosen-single select_query form-control sel" name="apply_source" style="width:186px;">
						<option value="">请选择</option>
						<option value="1" <?php echo $apply_source == '1' ? 'selected' : '';?>>微信申请</option>
						<option value="2" <?php echo $apply_source == '2' ? 'selected' : '';?>>现场办理</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label pull-left">是否超时：</label>
				<div class="pull-left" style="width:186px;">
					<select class="chosen-single select_query form-control sel" name="is_overtime" style="width:186px;">
						<option value="">请选择</option>
						<option value="0" <?php echo $is_overtime == '0' ? 'selected' : '';?>>未超时</option>
						<option value="1" <?php echo $is_overtime == '1' ? 'selected' : '';?>>已超时</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label pull-left">受理单号：</label>
				<div class="pull-left">
					<input type="text" class="form-control form-control-input" style="width:186px;" placeholder="受理单号" name="apply_number" value="<?php echo $apply_number;?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label pull-left">企业名称：</label>
				<div class="pull-left">
					<input type="text" class="form-control form-control-input" style="width:186px;" placeholder="企业名称" name="business_name" value="<?php echo $business_name;?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label pull-left">经营地址：</label>
				<div class="pull-left">
					<input type="text" class="form-control form-control-input" style="width:186px;" placeholder="经营地址" name="business_address" value="<?php echo $business_address;?>" />
				</div>
			</div>
			
			<div class="form-group">
				<label class="control-label pull-left">联系电话：</label>
				<div class="pull-left">
					<input type="text" class="form-control form-control-input" style="width:186px;" placeholder="联系电话" name="contact_tel" value="<?php echo $contact_tel;?>" />
				</div>
			</div>
			
			<div class="form-group">
				<label class="control-label pull-left">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</label>
				<div class="pull-left">
					<input type="text" class="form-control form-control-input" style="width:186px;" placeholder="姓名" name="contact_name" value="<?=$contact_name;?>" />
				</div>
			</div>
			
			<div class="form-group Labtime">
				<label class="control-label pull-left">申请时间：</label>
				<div class="pull-left">
					<div class="input-group search-link datetime" id="seldate">
						<input type="text" class="Wdate" id="startdate" name="startdate" placeholder="开始时间" value="<?php echo $startdate ?>" />
						<sapn class="hengxian">--</sapn>
						<input type="text" class="Wdate" id="enddate" name="enddate" placeholder="结束时间" value="<?php echo $enddate ?>"/>
						<input type="hidden" class="datetype" name="datetype" value="" />
					</div>
				</div>
			</div>

			<a class="btn btn-primary btn-sm pull-left btn_pattern" id="queryBtn" link="apply-apply">查&nbsp;询 </a>
			<!--每页显示记录数-->
			<input class="per_num" type="hidden" name="per_num" value="<?php echo $per_num?>" />
		</form>
	</div>
	<div class="clearfix"></div>

	<!-- 表格区域 -->
	<div class="infodata1 mainCons fenyes_lt">
		<?php if(!$tabledata_str){?>
			<!-- 没有数据显示 -->
			<div class="no_data">
				<img src="theme/images/data_none.png"  width="153" height="204" />
			</div>
		<?php }else{?>
			<!-- 数据存在显示 -->
			<div class="tablediv_cj_data background_color_lt">
				<table class="table1 cj_data table-bordered">

				</table>
			</div>

			<!-- 分页区域 -->
			<div class="bottom-handle">
				<div class="pull-left">
					<span>每页显示</span>
					<select class="linenum">
						<?php foreach($per_num_s as $v){?>
							<option <?php if($per_num==$v){echo ' selected = "selected"';}?> value="<?php echo $v ?>"><?php echo $v ?></option>
						<?php }?>
					</select>
					<span>条记录，</span>
					<span>一共 <?php echo $apply_num; ?> 条记录。</span>
				</div>
				<?php echo $page;?>
			</div>
		<?php }?>
	</div>
</div>
<script type="text/javascript">
	$(function(){
		var thepagenum = $('#activedisk').val();// 记录当前显示出的卡片编号
		var thepageclass = '.cj'+thepagenum;

		// 数据表格
		$('.cj_data').datatable({
			checkable:false,
			sortable:false,

			data: {
			cols: [
				{width: '4%', text: '序号', type: 'string', flex: false, sort: false,colClass:'text-center'},
				{width: '5%', text: '类型', type: 'string', flex: false, sort: false, colClass:'text-center'},
				{width: '5%', text: '姓名', type: 'string', flex: false, sort: false, colClass:'text-center'},
				{width: '8%', text: '电话', type: 'string', flex: false,sort: false, colClass:'text-center'},
				{width: '15%', text: '企业名称', type: 'string', flex: false, sort: false,colClass:'text-center'},
				{width: '8%', text: '许可证号', type: 'string', flex: false, sort: false, colClass:'text-center'},
				{width: '6%', text: '申请来源', type: 'string', flex: false, sort: false, colClass:'text-center'},
				{width: '6%', text: '当前进度', type: 'string', flex: false, sort: false, colClass:'text-center'},
				{width: '13%', text: '截止用时', type: 'string', flex: false, sort: false, colClass:'text-center'},
				{width: '10%', text: '申请时间', type: 'string', flex: false, sort: false,colClass:'text-center'},
				{width: '6%', text: '操作', type: 'string', flex: false, sort: false,colClass:'text-center'}
			],
			rows: [
				<?php echo $tabledata_str ?>
			]}
		});

		list_table();

		// 证件申请详情
		$('.certApplyDetails').click('click',function(){
			var id = $(this).attr('id');

				$.post('apply-applyDetailTab', {id:id}, function(data){
				var thepage = layer.open({
					type: 1,
					title: '申请详情',
					area: ['1000px', '620px'],
					zIndex: 0,
					shade: 0.3,
					shadeClose: true,
					offset: '50px',
					maxmin: false,
					content: data,
					id: 'applyDetailTab',
					success:function(){
						layer.closeAll('loading');
						return false;
					}
				});
				layer.full(thepage);
			});
		});

		// 删除证件申请
		$('.delApplyDetails').click('click',function(){
			var apply_id = $(this).attr('id');

			layer.confirm('确定删除申请信息？',function(index){
				// layer.close(index);
				var load = layer.load();
				$.ajax({
					data: {apply_id:apply_id},
					url:"apply-delApply",
					dataType:'json',
					type:'post',
					success:function(data){
						// alert(data);
						layer.close(load);
						if (data == 1) {
							layer.msg('成功！', {time: 1000, icon:1},function() {
								layer.closeAll();
								$('a[link="apply-apply"]').click();
							});
						} else {
							layer.msg('失败！', {time: 1000, icon:2},function() {
								layer.closeAll();
								$('a[link="apply-apply"]').click();
								// $('.main_content #querybtn[link="apply-apply"]').click();
							});
						}
					}
				});
			});
		});

		$(".select_query").chosen({
			width: '100%',
			placeholder_text: '',
			no_results_text: '没有找到',
			search_contains: true
		});
			
		// 条件查询
		$('#queryBtn').on('click',function(){
			var cur_page = 1;// 当前页数		
			var formdata = $('.conditions').serialize();// 表单序列化
			var link = $(this).attr('link');
			var idkeynum = $(this).closest(".cjall").attr('idkeynum');

			find_data_request(link,formdata,cur_page,idkeynum);// ajax页面查询按钮功能
		});

		// 分页
		$('.fenyes_lt .pager li').on('click',function(){
			var cur_page = $(this).attr('attr_page');								// 当前页数
				
			if($(this).attr('class') == 'next'){									// 点击下一页
				cur_page = $('.pager .active').attr('attr_page');
				cur_page = (cur_page*1)+1;
			}
			if($(this).attr('class') == 'previous'){								// 点击上一页
				cur_page = $('.pager .active').attr('attr_page');
				cur_page = (cur_page*1)-1;
			}
			
			var formdata = $('.conditions').serialize();						// 表单序列化
			var link = $(this).attr('link');
			var idkeynum = $(this).closest(".cjall").attr('idkeynum');

			formdata += '&cur_page='+cur_page;
			find_data_request(link,formdata,cur_page,idkeynum);
		});

		// 所属县局发生改变
		$('.area_type').on('change',function(){
            var county = $(this).val();
			// var area = $('.area_type option:selected').val();//选中的值

            $.ajaxSetup({
            	async: false
            });

			$('.progress-type').empty();
			$.post('apply-getTypeName',{county:county},function(data){
				// alert(data);
				if(data){
					$('.progress-type').html(data);
				}
			});
            
            $(".select_query").chosen({
                width: '100%',
                placeholder_text: '',
                no_results_text: '没有找到',
                search_contains: true
            });

            $('.select_query').trigger("chosen:updated"); 
		});
		
		//每页显示记录数改变
		$('.linenum').on('change',function(){
			$('.per_num').val($(this).val());
			$('#queryBtn').click();
		});
	});

	// ajax页面查询按钮功能
	function find_data_request(link,formdata,cur_page,idkeynum){
		layer_load();// 加载层
		$.get(link,formdata,function(data){
			layer.closeAll('loading'); // 关闭加载层
			data = '<div class="cjall cj'+idkeynum+'" idkeynum="'+idkeynum+'">'+data+'</div>';
			$('.cj'+idkeynum).replaceWith(data)
		},'html');
	}
</script>